﻿package net.wangit.util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class URLBean {

	HashMap<String, String> params;
	HttpServletRequest request;
	HttpServletResponse response;
	String page;

	public URLBean() {
	}

	public void setPage(String page) {
		this.page = page;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	@SuppressWarnings("unchecked")
	public String getURL() {
		Map fullParams = null;
		if (params != null)
			fullParams = new HashMap();
		if (page == null) {
			if (fullParams != null){
				fullParams.putAll(request.getParameterMap());
			}else{
				fullParams = request.getParameterMap();
			}
		}
		if (params != null) {
			fullParams.putAll(params);
		}
		return null;
	}

	public URLBean addParameter(String name, Object value) {
		if (params == null)
			params = new HashMap<String, String>();
		if (value == null)
			params.remove(name);
		else
			params.put(name, value.toString());
		return this;
	}

	public String toString() {
		return getURL();
	}
}
